import { defineStore } from "pinia";

const useUrlStore = defineStore("url", {
  state: () => ({
    openid: "",
    tagid: "",
    fid: 0,//查询点
    visit_id: 0,//途径点
    type: 0,
    bookid: "",//预约点
  }),
  getters: {},
  actions: {
    analysisUrl() {
      let query = window.location.search.substring(1);
      let vars = query.split("&");

      if (window.location.search === "") {
        vars = window.location.hash.replace(/#\/\?/, "").split("&");
      }
      for (let i = 0; i < vars.length; i++) {
        let pair = vars[i].split("=");

        switch (pair[0]) {
          case "openid":
            this.openid = pair[1];
            break;
          case "tagid":
            this.tagid = pair[1];
            break;
          case "fid":
            this.fid = +pair[1];
            break;
          case "visit_id":
            this.visit_id = +pair[1];
            break;
          case "type":
            this.type = +pair[1];
            break;
          case "bookid":
            this.bookid = pair[1];
            break;
          default:
            break;
        }
      }
      console.log('this.openid',this.openid);
      // console.log('this.tagid',this.tagid);
      // console.log('this.fid',this.fid);
      // console.log('this.visit_id',this.visit_id);
      // console.log('this.type',this.type);
      // console.log('this.bookid',this.bookid);
    },
  },
});

export default useUrlStore();
